package com.yc.shopping.util;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class ShoppingUtil {
	
	public static Map<String,Object> adminLogin = null; //登录成功管理员信息
	public static float totalPrice = 0;//当前结算用户的应收金额
	public static float actualCollection = 0;//实收金额
	/*
	 * 将对象转为字符串
	 */
	public static String objToString(Object obj) {
		if(obj == null) {
			return "";
		}
		return obj.toString();
	}
	
	//自动生成订单编号
	public static String genOrderId() {
		Date date = new Date();
		return "YC" + new SimpleDateFormat("yyyyMMddhhmmssSS").format(date);
	}
	
	public static void showMessage(Shell shell,String title,String message) {
		//登录失败
		//弹框提示
		MessageBox mb = new MessageBox(shell,SWT.NONE);
		mb.setText(title);
		mb.setMessage(message);
		mb.open();
	}
	
	/*
	 * 窗口居中
	 */
	public static void centerWindows(Shell shell) {
		//获取屏幕的大小
		Dimension demo = Toolkit.getDefaultToolkit().getScreenSize();
		shell.setLocation((demo.width - shell.getSize().x)/2, (demo.height - shell.getSize().y)/2);
	}
	
}
